import instance from '../../utils/axios'

// 1.全部频道列表
function getChannelsList () {
  return instance({
    url: '/v1_0/channels',
    method: 'get'
  })
}

export { getChannelsList }

// 2.获取文章列表（频道新闻推荐_V1.1）
function getArticles ({ channel_id, timestamp }) {
  return instance({
    url: '/v1_1/articles',
    method: 'get',
    params: { channel_id, timestamp, with_top: 1 }
  })
}
export { getArticles }

// 3.获取文章详情
function getArticleInfo (id) {
  return instance({
    url: `v1_0/articles/${id}`,
    method: 'get'
  })
}
export { getArticleInfo }

// 4.取消关注与关注接口
// 4.1关注用户：
function addFollowing ({ target }) {
  return instance({
    url: '/v1_0/user/followings',
    method: 'post',
    data: { target }
  })
}

// 取消关注(target是被取消关注的用户id)
function cannelFollowing (target) {
  return instance({
    url: `/v1_0/user/followings/${target}`,
    method: 'delete'
  })
}
// 5.点赞、取消(target:点赞的文章id)
function addPraise ({ target }) {
  return instance({
    url: '/v1_0/article/likings',
    method: 'post',
    data: { target }
  })
}
function canclePraise (target) {
  return instance({
    url: `/v1_0/article/likings/${target}`,
    method: 'delete'
  })
}
export { addFollowing, cannelFollowing, addPraise, canclePraise }

// 6.喜欢/取消喜欢(文章id)
function addLike (target) {
  return instance({
    url: `/v1_0/article/dislikes/${target}`,
    method: 'delete'
  })
}

function cancleLike ({ target }) {
  return instance({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: { target: target }
  })
}
export { addLike, cancleLike }

// 7.根据关键字搜索获取结果
function getSuggestion ({ q }) {
  return instance({
    url: '/v1_0/suggestion',
    method: 'get',
    params: { q }
  })
}
export { getSuggestion }

// 8.获取搜索结果列表
function getSearch (params) {
  return instance({
    url: '/v1_0/search',
    method: 'get',
    params
  })
}
export { getSearch }
